﻿using System;
using System.IO;

namespace TestRunner
{
    internal delegate void TextReceivedEventHandler(string str);
    internal delegate void GenericEventHandler();

    class OutputWriterStream : TextWriter
    {
        private readonly TextReceivedEventHandler textReceivedEventHandler;
        private readonly GenericEventHandler clearTextEventHandler;
        internal OutputWriterStream(TextReceivedEventHandler textReceivedEventHandler, GenericEventHandler clearTextEventHandler)
        {
            this.textReceivedEventHandler = textReceivedEventHandler;
            this.clearTextEventHandler = clearTextEventHandler;
        }

        public override System.Text.Encoding Encoding 
        {
            get { return System.Text.Encoding.Unicode; }
        }

        public override void WriteLine(string value)
        {
            textReceivedEventHandler(value);
        }

        public override void Flush()
        {
            clearTextEventHandler();
        }
    }
}